#!/bin/bash
# $Id: echo_failure,v 1.2 2004/08/03 20:32:14 repeater Exp $
# $Log: echo_failure,v $
# Revision 1.2  2004/08/03 20:32:14  repeater
# Changed the word timeout to failure for log statement.
#
# Revision 1.1  2004/08/03 19:37:07  repeater
# Initial revision
#
###########################################################
#                                                         #                  
#  Released under the GNU Public License                  #                  
#                                                         #                  
#  Script :  echo_end                                     #
#  Author :  Marcus Xenakis WA2DCI                        #
#  Version:  .15 Beta                                     #
#  Date   :  3/22/03                                      #
#  About  :  This script tests to see if the last call    #
#            was EchoLink or IRLP. Passes to normal IRLP  #
#            "end" script if not an EchoLink call         #
#                                                         #
###########################################################

[ -z "$ECHO_SCRIPT" ] && ECHO_SCRIPT=/home/EchoIRLP/scripts
   source $ECHO_SCRIPT/echo_common

killall imike >/dev/null 2>&1
killall ispeaker >/dev/null 2>&1

$BIN/key

NODE_CALL="`cat $LOCAL/echo_call`"

#LOGS the disconnect 
log "Connect failure from EchoLink `cat $LOCAL/echo_active` $NODE_CALL"

if [ -f "$LOCAL"/echoirlp ] ; then
  # Disconnect from destination node
  TBD_COMMAND disconnect all
  echo "${0##*/}: TBD_COMMAND $NODE_CALL"
  rm -f "$LOCAL"/echoirlp
else
# Otherwise we're using a shared conference - update our status
  "$ECHO_BIN"/echostatus $ECHO_SERVER O
fi

# Save Node numbers
NODE_ID=`cat "$LOCAL"/echo_active`
CONVERTED_STATIONID=`cat "$LOCAL"/active`

#if [ "$ECHO_SAY_NODE" = "NO" ] ; then
#  "$ECHO_SCRIPT"/echo_wavplay echolinkoff
#else 
#  "$ECHO_SCRIPT"/echo_wavplay echolinkoff echo_id
#fi

# remove status flags
rm -f "$LOCAL"/echo_active
rm -f "$LOCAL"/echo_call
rm -f "$LOCAL"/codec
rm -f "$LOCAL"/selectcodec
rm -f "$LOCAL"/udp_port
rm -f "$LOCAL"/preaccess
rm -f "$LOCAL"/connectedip
rm -f "$LOCAL"/calledip
rm -f "$RUN"/*
rm -f "$LOCAL"/echo_active
rm -f "$LOCAL"/active
rm -f "$LOCAL"/node_id
rm -f "$LOCAL"/echoirlp

# Reset timeout
touch "$LOCAL"/timeout

#added for the really fast machines :)
sleep 1

if [ "$CUSTOM_OFF" = "YES" ] ; then
  if [ -f "$CUSTOM"/custom_off ] ; then
    "$CUSTOM"/custom_off $1
  fi
fi

# Update IRLP status
"$SCRIPT"/statupdate &

# Update WA2DCI Status
eval `echo "$CONVERTED_STATIONID" | awk '//{print "NODE="substr($NODE,4,4)}'`
PARM=$NODE:$CALLSIGN:0:OFF
URL="http://xenakis.net/wa2dci/echoirlp/statupdate.php?"
#lynx -auth=zombo:swazzi -source "$URL$PARM" > /dev/null &

"$SCRIPT"/failure $1 call

"$BIN"/unkey

exit 0
